package chapter15;

/**
 * @author lzy
 * @version v1.0
 * Create DateTime: 2019/3/14 17:12
 */
class FixedSizeStack<T>{
    private int index = 0;
    private Object[] storage;

    public FixedSizeStack(int size) {
        storage = new Object[size];
    }

    public void push(T item){
        storage[index++] = item;
    }

    public T pop(){
        return (T) storage[--index];
    }
}

public class GenericCast {
    public static final int SIZE = 10;

    public static void main(String[] args) {
        FixedSizeStack<String> stack = new FixedSizeStack<>(SIZE);
        for (String s : "a b c d e f g h i j".split(" ")) {
            stack.push(s);
        }

        for (int i = 0; i < SIZE; i++) {
            System.out.println(stack.pop());
        }
    }
}
